package com.andreas.springRabbitMQ;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述：spring整合RabbitMQ消息发送者
 */
public class Sender {
    public static void main(String[] args) {
        // 1.创建spring容器
        ClassPathXmlApplicationContext context = new
                ClassPathXmlApplicationContext("spring/spring-rabbitmq-producer.xml");
        // 2.从容器中获取对象
        RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
        // 3.发送消息
        Map<String, String> map = new HashMap<>();
        map.put("name", "周乾");
        map.put("email", "1292184670@qq.com");
        rabbitTemplate.convertAndSend(map);
        context.close();
    }
}
